using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace 水库上位机
{
    public class UPum : Control
    {
        private bool isRunning = false;
        private string pumpName = "抽水泵";

        [Category("行为")]
        [Description("是否运行")]
        public bool IsRunning
        {
            get { return isRunning; }
            set 
            {
                isRunning = value;
                this.Invalidate();
            }
        }

        [Category("外观")]
        [Description("水泵名称")]
        public string PumpName
        {
            get { return pumpName; }
            set 
            {
                pumpName = value;
                this.Invalidate();
            }
        }

        public UPum()
        {
            this.DoubleBuffered = true;
            this.ResizeRedraw = true;
            this.Size = new Size(120, 80);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;

            int centerX = this.Width / 2;
            int centerY = this.Height / 2;

            // 绘制泵体
            using (Brush brush = new SolidBrush(Color.Gray))
            {
                g.FillRectangle(brush, centerX - 40, centerY - 20, 80, 40);
            }
            using (Pen pen = new Pen(Color.Black, 2))
            {
                g.DrawRectangle(pen, centerX - 40, centerY - 20, 80, 40);
            }

            // 绘制叶轮
            using (Pen pen = new Pen(Color.DarkGray, 3))
            {
                g.DrawEllipse(pen, centerX - 15, centerY - 15, 30, 30);
                for (int i = 0; i < 6; i++)
                {
                    double angle = Math.PI * 2 * i / 6;
                    int x1 = centerX + (int)(Math.Cos(angle) * 10);
                    int y1 = centerY + (int)(Math.Sin(angle) * 10);
                    int x2 = centerX + (int)(Math.Cos(angle) * 15);
                    int y2 = centerY + (int)(Math.Sin(angle) * 15);
                    g.DrawLine(pen, x1, y1, x2, y2);
                }
            }

            // 绘制进出水口
            using (Pen pen = new Pen(Color.Black, 3))
            {
                g.DrawLine(pen, centerX - 40, centerY, centerX - 60, centerY);
                g.DrawLine(pen, centerX + 40, centerY, centerX + 60, centerY);
            }

            // 绘制水泵名称
            using (Font font = new Font("微软雅黑", 9F, FontStyle.Bold))
            {
                using (Brush brush = new SolidBrush(Color.Black))
                {
                    SizeF textSize = g.MeasureString(pumpName, font);
                    g.DrawString(pumpName, font, brush, (this.Width - textSize.Width) / 2, this.Height - 20);
                }
            }

            // 绘制状态指示器
            using (Brush brush = new SolidBrush(isRunning ? Color.Green : Color.Red))
            {
                g.FillEllipse(brush, centerX - 5, centerY - 45, 10, 10);
            }
            using (Pen pen = new Pen(Color.Black, 1))
            {
                g.DrawEllipse(pen, centerX - 5, centerY - 45, 10, 10);
            }

            // 绘制状态文本
            using (Font font = new Font("微软雅黑", 7F))
            {
                using (Brush brush = new SolidBrush(Color.Black))
                {
                    string status = isRunning ? "运行中" : "已停止";
                    g.DrawString(status, font, brush, centerX - 15, centerY - 50);
                }
            }
        }
    }
}